<template>
  <div class="association-news" v-if="list.length">
    <div class="divider_header">
      <div class="titel">
        <div class="divider divider-l"></div>
        <h5>协会资讯</h5>
        <div class="divider divider-r"></div>
      </div>
      <div class="more" @click="$router.push('/dynamic/news')">
        <span>更多协会资讯</span>
        <img src="@/assets/home_more.png" alt="" />
      </div>
    </div>
    <div class="content">
      <div class="carousel">
        <el-carousel
          indicator-position="none"
          :interval="3000"
          :height="pageW >= 1920?'525px':pageW >= 1600 && pageW < 1920?'426px':pageW >= 1400 && pageW < 1600?'392px':'370px'"
          @change="carouserChange"
        >
          <el-carousel-item v-for="(item, index) in list" :key="index">
            <img
              v-if="item.newsCover"
              :src="item.newsCover"
              @click="jump(item.associationNewsId)"
              alt=""
            />
            <img
              v-else
              src="@/assets/default.jpg"
              @click="jump(item.associationNewsId)"
              alt=""
            />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="list">
        <div
          v-for="(item, index) in list"
          :key="index"
          :class="{ active: index == currentIndex }"
          @click="jump(item.associationNewsId)"
        >
          <span class="titel">{{ item.newsTitle }}</span>
          <span class="time" :class="{ active: index == currentIndex }">{{
            item.publishTime | formatDate
          }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script >
export default {
  props: ["list"],
  data() {
    return {
      currentIndex: 0,
       pageW: 1920,
    };
  },
   mounted() {
    this.pageW = window.screen.width;
  },
  methods: {
    carouserChange(val) {
      this.currentIndex = val;
    },
    jump(id) {
      this.$router.push(`/newsDetail/${id}`);
    },
  },
};
</script>
<style lang="less">
.association-news {
  width: 75%;
  background-color: #fff;
  padding: 78px 0 0 0;
  margin: 0 auto;
  box-sizing: border-box;
  .content {
    display: flex;
    font-size: 1.5rem;
    .carousel {
      flex: 1;
      width: 50%;
      margin-right: 1%;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .list {
      width: 50%;
      box-sizing: border-box;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      .active {
        color: #0b4e9e !important;
      }
      > div {
        width: 100%;
        cursor: pointer;
        display: flex;
        align-items: center;
        .titel {
          padding-left: 8px;
          margin-right: 1rem;
          width: 63%;
          overflow: hidden; //超出的文本隐藏
          text-overflow: ellipsis; //溢出用省略号显示
          white-space: nowrap; //溢出不换行
        }
        .time {
          font-size: 16px;
          color: #666;
          text-align: left;
        }
      }
    }
  }
}
</style>